<template>
  <div class="app-container" v-loading="loading">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <!-- <el-form-item label="检测开始日期" prop="checkStartDate">
        <el-date-picker
          clearable
          v-model="queryParams.checkStartDate"
          type="date"
          value-format="yyyy-MM-dd 00:00:00"
          placeholder="请选择开始日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="检测结束日期" prop="checkEndDate">
        <el-date-picker
          clearable
          v-model="queryParams.checkEndDate"
          type="date"
          value-format="yyyy-MM-dd 23:59:59"
          placeholder="请选择结束日期"
        ></el-date-picker>
      </el-form-item>-->
      <el-form-item label="送检单号" prop="inspectionNumber">
        <el-input v-model="queryParams.inspectionNumber" placeholder="请输入送检单号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工单编号" prop="projectCode">
        <el-input v-model="queryParams.projectCode" placeholder="请输入工单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品规格" prop="productSpec">
        <el-input v-model="queryParams.productSpec" placeholder="请输入产品规格" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="客户" prop="clientName">
        <el-input v-model="queryParams.clientName" placeholder="请输入客户名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="合同号" prop="fText4">
        <el-input v-model="queryParams.fText4" placeholder="请输入合同号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择状态" clearable>
          <el-option v-for="item in inspectState" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="检验结果" prop="checkResult">
        <el-select v-model="queryParams.checkResult" placeholder="请选择检验结果" clearable>
          <el-option v-for="item in inspectResult" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="SN码" prop="snCode">
        <el-input v-model="queryParams.snCode" placeholder="请输入SN码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="技术分解单号" prop="fText1">
        <el-input v-model="queryParams.fText1" placeholder="请输入技术分解单号" clearable @keyup.enter.native="fText1" />
      </el-form-item>

      <el-form-item label="检验日期">
        <el-date-picker v-model="queryParams.time" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['mes:qc:fqc:export']">导出</el-button>
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mes:qc:qcindex:add']"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table v-loading="loading" :data="qcindexList" height="calc(100vh - 285px)">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column type="index" label="序号" align="center" width="50" />
      <el-table-column label="送检单号" align="center" prop="inspectionNumber" width="160">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)">{{
            scope.row.inspectionNumber
          }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="工单编码" width="100" align="center" prop="projectCode"></el-table-column>
      <el-table-column label="产品编码" width="100" align="center" prop="productCode"></el-table-column>
      <el-table-column label="产品名称" width="120" align="center" prop="productName"></el-table-column>
      <el-table-column label="产品规格" align="center" prop="productSpec" min-width="200"></el-table-column>
      <el-table-column label="客户" width="120" align="center" prop="clientName"></el-table-column>
      <el-table-column label="合同号" width="120" align="center" prop="ftext4"></el-table-column>
      <el-table-column label="技术分解单号" width="150" align="center" prop="ftext1"></el-table-column>
      <el-table-column label="数量" width="80" align="center" prop="quantityDeclared"></el-table-column>
      <el-table-column label="报检日期" width="100" align="center" prop="deliveryTime"></el-table-column>
      <el-table-column label="状态" align="center" prop="state" class="state">
        <template slot-scope="scope">
          <div :style="{ color: scope.row.state == '0' ? 'orange' : '' }">
            {{
              scope.row.state == "0"
                ? "未检验"
                : scope.row.state == "1"
                  ? "已检验"
                  : scope.row.state == "2"
                    ? "入库单已撤回"
                    : scope.row.state == "3"
                      ? "撤回"
                      : "未检验"
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="检验结果" align="center" prop="checkResult" width="80">
        <template slot-scope="scope">
          <div :style="{ color: scope.row.checkResult == '0' ? 'red' : 'green' }">
            {{
              scope.row.checkResult == "0"
                ? "不合格"
                : scope.row.checkResult == "1"
                  ? "合格"
                  : "--"
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="检验员" align="center" prop="checkUser"></el-table-column>
      <el-table-column label="检验日期" align="center" prop="provingTime" width="100"></el-table-column>
      <!-- <el-table-column label="审核人" align="center" prop="auditor"></el-table-column>
      <el-table-column label="审核日期" align="center" prop="auditTime"></el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="140px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUserRole(scope.row)" v-if="scope.row.checkResult != '1' && scope.row.reportStatus != '0'" v-hasPermi="['mes:qc:fqc:check']">检验</el-button>
          <el-button :disabled="scope.row.from && scope.row.from == 'return_notice'" size="mini" type="text" icon="el-icon-edit" @click="handleViewBom(scope.row)" v-hasPermi="['mes:qc:bom:view']">BOM详情</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mes:qc:qcindex:remove']"
          >删除</el-button>-->

          <!-- 2024-12-13 djj 新增 撤回 按钮 -->
          <el-button size="mini" type="text" icon="el-icon-printer" v-if="scope.row.state == 2" @click="handleRetract(scope.row)">撤回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改检测项对话框 -->
    <el-drawer :title="title" :visible.sync="open" size="75%" :before-close="cancel" custom-class="demo-drawer" v-loading="isDrawerLoading">
      <div class="demo-drawer__content dialogContent">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-row>
            <el-col :span="8">
              <el-form-item label="产品编码" prop="productCode">
                <el-input v-model="form.productCode" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="产品名称" prop="productName">
                <el-input v-model="form.productName" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="产品规格" prop="productSpec">
                <el-input v-model="form.productSpec" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="客户" prop="clientName">
                <el-input v-model="form.clientName" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="合同号" prop="ftext4">
                <el-input v-model="form.ftext4" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="技术分解号" prop="ftext1">
                <el-input v-model="form.ftext1" placeholder />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="报检数量" prop="quantityDeclared">
                <el-input v-model="form.quantityDeclared" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="检验类型" prop="fqcInspectionType">
                <el-select v-model="form.fqcInspectionType" placeholder="请选择检验类型" @change="selectChange" :disabled="isReview">
                  <el-option label="全检" value="0"></el-option>
                  <el-option label="抽检" value="1"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6" v-if="form.fqcInspectionType == '1'">
              <el-form-item label="抽样数量" prop="sampleNumber">
                <el-input-number :controls="false" v-model="form.sampleNumber" :disabled="optType == 'add' ? false : true" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="合格数量" prop="qualifiedCode">
                <el-input v-model="form.qualifiedCode" placeholder :disabled="optType == 'add' ? false : true" @change="(value) =>
                  autoInput(value, 'qualifiedCode', 'unqualifiedCode')
                " />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="不合格数量" prop="unqualifiedCode">
                <el-input v-model="form.unqualifiedCode" placeholder :disabled="optType == 'add' ? false : true" @change="(value) =>
                    autoInput(value, 'unqualifiedCode', 'qualifiedCode')
                  " />
              </el-form-item>
            </el-col>
            <!-- add begin by zyj 2024/11/12 添加扫SN码-->
            <el-col :span="6">
              <el-form-item label="扫码">
                <el-input v-model="snCode" placeholder="请输入扫码" type="textarea" @keyup.enter.native="scanCodeHandler" :disabled="isReview" />
              </el-form-item>
            </el-col>
            <!-- add end by zyj 2024/11/12 添加扫SN码-->
          </el-row>
          <!-- add begin by zyj 2025/01/09 添加质检方案-->
          <el-row>
            <el-col :span="6">
              <el-form-item label="质检方案" prop="InspectionScheme">
                <el-select v-model="form.InspectionScheme" filterable placeholder="请选择" @change="InspectionChange">
                  <el-option v-for="item in InspectionSchemeList" :key="item.fid" :label="item.fname" :value="item.fid" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- add end by zyj 2025/01/09 添加质检方案-->
          <el-row>
            <el-col :span="24">
              <el-form-item label="SN码">
                <div>
                  <!-- <div>
                    <el-checkbox
                      :indeterminate="isIndeterminate"
                      v-model="checkAll"
                      @change="handleCheckAllChange"
                    >全选</el-checkbox>
                  </div>-->
                  <el-checkbox-group v-model="snList" :disabled="isReview">
                    <el-checkbox v-for="item in snCodeAllList" :label="item" :key="item">{{ item }}</el-checkbox>
                  </el-checkbox-group>
                </div>
              </el-form-item>
            </el-col>
          </el-row>

          <!-- add begin by zyj 2024/11/15 添加全选-->
          <el-row>
            <el-col :span="24">
              全选：<el-radio-group v-model="allCheck" :disabled="isReview">
                <el-radio :label="1">√</el-radio>
                <el-radio :label="0">×</el-radio>
              </el-radio-group>
            </el-col>
          </el-row>
          <!-- add end by zyj 2024/11/15 添加全选-->
          <el-row>
            <el-table v-loading="loading1" :data="templateList" :span-method="objectSpanMethod">
              <el-table-column label="类型" align="center" prop="indexType" width="160px">
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.mes_index_type" :value="scope.row.indexType" />
                </template>
              </el-table-column>
              <el-table-column type="index" width="50"></el-table-column>
              <el-table-column label="检测项目" align="center" prop="indexName" width="260px" />

              <el-table-column align="center" prop="checkResult" width="240px" label="检查结果">
                <!-- <template slot="header" slot-scope="scope">
                  <div class="headerDiv" v-if="optType=='add' || optType=='edit'">
                    <el-input
                      v-model="snObj[`snCode${i}`]"
                      size="mini"
                      placeholder="输入sn码"
                      @input="snbutton"
                      id="sncode-input"
                    />
                  </div>
                  <div v-if="optType=='view'">{{ snObj[`snCode${i}`] }}</div>
                </template>-->{{ optType }}
                <template slot-scope="scope">
                  <div v-if="optType == 'add' || optType == 'edit'">
                    <el-radio-group v-model="scope.row.checkResult" @input="checkChange">
                      <el-radio :label="1" :value="1">√</el-radio>
                      <el-radio :label="0" :value="0">×</el-radio>
                    </el-radio-group>
                    <ul v-if="scope.row.attrObj.type == '2'">
                      <li class="mInput">
                        <span>标准值</span>
                        <el-input v-model="scope.row.attrObj.standard" style="width: 70px" @input="(e) => inputStandard(e, scope.row, scope.$index)
                        " />
                        <el-input v-model="scope.row.attrObj.num" style="width: 70px" @input="(e) => inputStandard(e, scope.row, scope.$index)
                        " />
                      </li>
                    </ul>
                    <ul v-if="scope.row.attrObj.type == '4'">
                      <li class="mInput">
                        <span>长</span>
                        <el-input v-model="scope.row.attrObj.lStandard" style="width: 70px" @input="(e) => inputCheckout(e, scope.row, scope.$index)
                        " />
                        <el-input v-model="scope.row.attrObj.lNum" style="width: 70px" @input="(e) => inputCheckout(e, scope.row, scope.$index)
                        " />
                      </li>
                      <li class="mInput">
                        <span>宽</span>
                        <el-input v-model="scope.row.attrObj.wStandard" style="width: 70px" @input="(e) => inputCheckout(e, scope.row, scope.$index)
                        " />
                        <el-input v-model="scope.row.attrObj.wNum" style="width: 70px" @input="(e) => inputCheckout(e, scope.row, scope.$index)
                        " />
                      </li>
                      <li class="mInput">
                        <span>高</span>
                        <el-input v-model="scope.row.attrObj.hStandard" style="width: 70px" @input="(e) => inputCheckout(e, scope.row, scope.$index)
                        " />
                        <el-input v-model="scope.row.attrObj.hNum" style="width: 70px" @input="(e) => inputCheckout(e, scope.row, scope.$index)
                        " />
                      </li>
                    </ul>
                  </div>
                  <div v-if="optType == 'view'">
                    <div style="font-size: 20px">
                      {{
                        scope.row.checkResult == "0"
                          ? "×"
                          : scope.row.checkResult == "1"
                            ? "√"
                            : "--"
                      }}
                    </div>
                    <div v-if="scope.row.attrObj.type == '2'">
                      <div class="mInput">
                        <span>标准值</span>
                        <span>{{ scope.row.attrObj.standard }}：</span>
                        <span>{{ scope.row.attrObj.num }}</span>
                      </div>
                    </div>
                    <ul v-if="scope.row.attrObj.type == '4'">
                      <li class="mInput">
                        <span>长</span>
                        <span>{{ scope.row.attrObj.lStandard }},</span>
                        <span>{{ scope.row.attrObj.lNum }}</span>
                      </li>
                      <li class="mInput">
                        <span>宽</span>
                        <span>{{ scope.row.attrObj.wStandard }},</span>
                        <span>{{ scope.row.attrObj.wNum }}</span>
                      </li>
                      <li class="mInput">
                        <span>高</span>
                        <span>{{ scope.row.attrObj.hStandard }},</span>
                        <span>{{ scope.row.attrObj.hNum }}</span>
                      </li>
                    </ul>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </el-row>

          <el-row>
            <el-col :span="24" class="imgDiv">
              <el-form-item label="检验结果" prop="checkResult">
                <el-radio-group v-model="form.checkResult" :disabled="isReview">
                  <el-radio :label="1">√</el-radio>
                  <el-radio :label="0">×</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <!-- :disabled="form.state =='0'?false:true" -->
            <el-col :span="24">
              <el-form-item label="备注:" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="输入备注" :disabled="isReview" style="width: 450px; height: 50px"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <!-- 不合格品异常记录列表 -->
          <div v-if="form.checkResult == 0">
            <el-form-item label="不合格品处理方式" prop="repairState">
              <el-radio-group v-model="form.repairState" v-if="optType != 'view' && !isReview">
                <el-radio :label="1">返工</el-radio>
                <el-radio :label="2">返修</el-radio>
                <el-radio :label="3">让步接收</el-radio>
              </el-radio-group>
              <span v-if="optType == 'view'">
                ：
                {{
                  form.repairState == "1"
                    ? "返工"
                    : form.repairState == "2"
                      ? "返修"
                      : "--"
                }}
              </span>
            </el-form-item>

            <el-form-item label="异常记录">
              <el-table :data="exceptionLogList">
                <el-table-column label="类型选择" align="center" prop="indexType">
                  <template slot-scope="scope">
                    <el-select v-model="scope.row.indexType" placeholder="请选择检测项类型" clearable :disabled="isReview">
                      <el-option v-for="(dict, index) in errorTypeList" :key="index" :label="dict.label" :value="dict.indexTypeName" />
                    </el-select>
                  </template>
                </el-table-column>

                <el-table-column label="异常描述" align="center" prop="describeData">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.describeData" placeholder type="textarea" :disabled="isReview" />
                  </template>
                </el-table-column>
                <el-table-column label="文件上传" align="center" prop="fileName">
                  <template slot-scope="scope">
                    <ImageUpload :limit="1" :value="scope.row.fileName" :fileSize="15" @input="(url) => handleImgUplaoded(url, scope.$index)" @onRemoved="(url) => handleImgRemoved(url, scope.$index)" :disabled="isReview"></ImageUpload>
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button size="medium" type="text" icon="el-icon-circle-plus-outline" @click="errorAdd(item)"></el-button>
                    <el-button v-if="scope.$index != 0" size="medium" type="text" icon="el-icon-remove-outline" @click="errorDel(scope.$index)"></el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </div>
        </el-form>
      </div>
      <div class="demo-drawer__footer" style="text-align: right">
        <el-button type="primary" @click="cancel" v-if="optType == 'view'">返回</el-button>
        <el-button type="primary" @click="submitFormBtn" :disabled="fqcDisabled" v-else>确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-drawer>

    <DetailsList v-if="openDetail" ref="detailsList"></DetailsList>
    <DetailsBom v-if="openDetailBom" ref="detailsBom"></DetailsBom>
    <!--2024-12-27 djj 新增 复核详情弹出框 -->
    <ReviewDetails ref="reviewDetails"></ReviewDetails>
  </div>
</template>

<script>
import {
  listInspection,
  getInspection,
  delInspection,
  addInspection,
  updateInspection,
  templateindexList,
  listError,
  checkSncode,
  getFqcSnCode, revoke, inspectionQE, getCheckItems, fqcReject
} from "@/api/mes/qc/fqc";
import { qcschemeAll, qcscheme } from "@/api/mes/qc/iqc";
import { getAdminList, } from "@/api/system/follow";
import { getTemplateId } from "@/api/mes/qc/templateproduct";
import { selectUserRole } from "@/api/mes/pro/workorder";
import { genCode } from "@/api/mes/md/rule";
import DetailsList from "./components/detailsList.vue";
import DetailsBom from "./components/detailsBom.vue";
import ReviewDetails from "./components/reviewDetails.vue";
export default {
  name: "Fqc",
  dicts: ["mes_index_type", "mes_qc_result"],
  components: { DetailsList, DetailsBom, ReviewDetails },
  data() {
    return {
      //自动生成编码
      autoGenFlag: false,
      optType: undefined,
      openDetail: false,
      openDetailBom: false,
      allCheck: -1,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      fqcDisabled: false,
      // 显示搜索条件
      showSearch: true,
      //质检方案
      InspectionSchemeList: [],
      // 总条数
      total: 0,
      // 检测项表格数据
      qcindexList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        indexName: null,
        indexType: null,
        qcTool: null,
        inspectionNumber: null,
        projectCode: null,
        productName: null,
        productSpec: null,
        clientName: null,
        fText4: null,
        state: null,
        checkResult: null,
        snCode: null,
        fText1: null,
      },
      // 表单参数
      form: {},
      // sncode集合
      snObj: {},
      radioObj: {},
      // 表单校验
      rules: {
        snCode: [{ required: true, message: "SN码不能为空", trigger: "blur" }],
        unqualifiedCode: [
          { required: true, message: "不合格数量不能为空", trigger: "blur" },
        ],
        qualifiedCode: [
          { required: true, message: "合格数量不能为空", trigger: "blur" },
        ],
        checkResult: [
          { required: true, message: "检验结果不能为空", trigger: "change" },
        ],

        headEndCheckType: [
          { required: true, message: "类型不能为空", trigger: "change" },
        ],
        fqcInspectionType: [
          { required: true, message: "检验类型不能为空", trigger: "change" },
        ],
        InspectionScheme: [
          { required: true, message: "质检方案不能为空", trigger: "change" },
        ],
      },
      indexCodeDisabled: false,
      // 模板列表
      templateList: [],
      snCode: '',
      loading1: false,
      spanArr: [],
      // 异常记录列表
      exceptionLogList: [{}],
      // 不合格数
      failedSncode: [],
      // 首页列表信息
      QcFqcAcInspectionHead: {},
      //FQC不良类别
      errorTypeList: [
        {
          label: "标识不良",
          indexTypeName: "标识不良",
        },
        {
          label: "名牌不良",
          indexTypeName: "名牌不良",
        },
        {
          label: "LOGO、丝印不良",
          indexTypeName: "LOGO、丝印不良",
        },
        {
          label: "机箱外观不良",
          indexTypeName: "机箱外观不良",
        },
        {
          label: "线材不良",
          indexTypeName: "线材不良",
        },
        {
          label: "物料不良",
          indexTypeName: "物料不良",
        },
        {
          label: "螺钉记号不良",
          indexTypeName: "螺钉记号不良",
        },
        {
          label: "螺钉漏打",
          indexTypeName: "螺钉漏打",
        },
        {
          label: "螺钉未打紧",
          indexTypeName: "螺钉未打紧",
        },
        {
          label: "接线不良",
          indexTypeName: "接线不良",
        },
        {
          label: "接线紧固不良",
          indexTypeName: "接线紧固不良",
        },
        {
          label: "装配不良",
          indexTypeName: "装配不良",
        },
        {
          label: "接线走线不符合工艺要求",
          indexTypeName: "接线走线不符合工艺要求",
        },
        {
          label: "打胶不良",
          indexTypeName: "打胶不良",
        },
        {
          label: "软件版本不良",
          indexTypeName: "软件版本不良",
        },
        {
          label: "参数设置不良",
          indexTypeName: "参数设置不良",
        },
        {
          label: "CAN电阻不良",
          indexTypeName: "CAN电阻不良",
        },
        {
          label: "拨码不良",
          indexTypeName: "拨码不良",
        },
        {
          label: "调试报告不良",
          indexTypeName: "调试报告不良",
        },
        {
          label: "配件不齐",
          indexTypeName: "配件不齐",
        },
        {
          label: "挡板、挡板螺丝漏",
          indexTypeName: "挡板、挡板螺丝漏",
        },
      ],
      snCodeAllList: [],
      snList: [],
      //检验状态
      inspectState: [
        {
          value: 0,
          label: "未检验",
        },
        {
          value: 1,
          label: "已检验",
        },
        {
          value: 2,
          label: "入库单已撤回",
        },
        {
          value: 3,
          label: "撤回",
        },
      ],
      //检验结果
      inspectResult: [
        {
          value: 1,
          label: "合格",
        },
        {
          value: 0,
          label: "不合格",
        },
      ],
      /* 2024-12-27 djj 新增人员列表 */
      btnType: '',
      adminList: [],
      currentUser: this.$store.state.user.name,
      // 是否是复核状态，是则编辑框禁用
      isReview: false,
      isDrawerLoading: false,
    };
  },
  created() {
    this.getList();
    this.getAdminData();
    // this.getErrorlist()
  },
  watch: {
    // add begin by zyj 2024/11/15 添加全选
    allCheck: {
      handler(val) {
        let arr = this.deepClone(this.templateList);
        arr.forEach(item => item['checkResult'] = val)
        this.templateList = arr;
        this.form.checkResult = val;
      },
      immediate: true,
    }
    // add end by zyj 2024/11/15 添加全选
  },
  methods: {
    // add begin by zyj 2025/01/09 添加质检方案
    //查询质检方案list
    getQualityinspection() {
      qcschemeAll().then((res) => {
        console.log(res, "质检方案的list");
        if (res.code == 200) {
          this.InspectionSchemeList = res.data;
        }
      });
    },
    //质检方案下拉change事件
    InspectionChange(value) {
      console.log(value, "质检方案下拉change事件");
      let params = {
        fid: value,
        quantityCheck: 0,
      };
      qcscheme(params).then((res) => {
        console.log(res, "根据id查询质检方案的res");
        res.data.qcIqcInspectionItemList.forEach((item) => {
          if (item.analysisMethod != "1") {
            item.checkResult = 1;
          }
        });
        this.templateList = res.data.qcIqcInspectionItemList.map((item, index) => {
          return Object.assign(item, { indexType: item.inspectionItem, indexName: item.inspectionStandard }, {
            attrObj: item.attr1 ? JSON.parse(item.attr1) : { type: "0" },
          });
        });
        // this.templateList = res.data.qcIqcInspectionItemList;
        this.getSpanArr(res.data.qcIqcInspectionItemList);
        // this.abnormalList = this.templateList.map((item) => {
        //   return item.inspectionItem;
        // });

        // this.spotCheck();
      });
    },
    // add end by zyj 2025/01/09 添加质检方案
    /* 2024-12-29 djj 新增 驳回 按钮 */
    handleReject(row) {
      this.$confirm('是否确认驳回该检验单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        fqcReject({ id: row.id }).then(() => {
          this.getList();
          this.$message({
            type: 'success',
            message: '驳回成功!'
          });
        }).catch(() => { })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    /* 2024-12-24 djj 新增人员列表 */
    getAdminData() {
      let param = {
        pageNum: 1,
        pageSize: 10000,
        deptId: '491277'
      };
      getAdminList(param).then((res) => {
        this.adminList = res.rows ? res.rows : [];
      });
    },
    /* 2024-12-13 djj 撤回 */
    handleRetract(row) {
      this.$confirm('确定要撤回吗？', '提示', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确认',
        cancelButtonText: '取消'
      })
        .then(() => {
          revoke({ id: row.id }).then((res) => {
            this.$message.success("撤回成功");
            this.getList();
          }).catch(() => { })
        })
        .catch(action => { });

    },

    // add begin by zyj 2024/11/12 添加扫SN码
    scanCodeHandler() {
      // this.snCodeAllList.filter(item => item.snCode === this.snCode).forEach(
      //   item => {
      //     item['isCheck'] = true;
      //   }
      // )

      // this.snList.push(this.snCode)
      // this.checkAll = this.snCodeAllList.length === this.snList.length;
      // this.isIndeterminate = this.snList.length > 0 && this.snList.length < this.snCodeAllList.length;
      // this.snCode = ''
      // 拆分 SN 字符串，支持换行、逗号、空格等分隔符
      const inputSNList = this.snCode
        .split(/[\n,\s]+/)         // 按换行符、逗号、空格分隔
        .map(sn => sn.trim())      // 去掉前后空格
        .filter(sn => sn);         // 去除空字符串

      // 遍历 SN 列表，更新 isCheck 标记
      inputSNList.forEach(sn => {
        this.snCodeAllList.forEach(item => {
          if (item.snCode === sn) {
            item.isCheck = true;
          }
        });

        // 避免重复添加
        if (!this.snList.includes(sn)) {
          this.snList.push(sn);
        }
      });

      // 更新 checkAll 和 isIndeterminate 状态
      const total = this.snCodeAllList.length;
      const selected = this.snList.length;
      this.checkAll = selected === total;
      this.isIndeterminate = selected > 0 && selected < total;

      // 清空输入框
      this.snCode = '';

    },
    // add end by zyj 2024/11/12 添加扫SN码
    handleExport() {
      console.log(this.queryParams, "=====queryParams===");
      if (this.queryParams.time) {
        this.queryParams["provingTimeBegin"] =
          this.queryParams.time[0].split(" ")[0];
        this.queryParams["provingTimeEnd"] =
          this.queryParams.time[1].split(" ")[0];
      } else {
        this.queryParams["provingTimeBegin"] = null;
        this.queryParams["provingTimeEnd"] = null;
      }
      this.download(
        "/mes/head/export",
        {
          ...this.queryParams,
        },
        `fqc_${new Date().getTime()}.xlsx`
      );
    },
    /** 查询检测项列表 */
    getList() {
      this.loading = true;
      listInspection(this.queryParams).then((response) => {
        this.qcindexList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getErrorlist(type, id) {
      // let params = {};
      // params.productType = type;
      // params.templateId = id;
      // console.log(params, "params");
      // listError(params).then(response => {
      //   this.errorTypeList = response.data;
      //   console.log(response, "异常记录list");
      // });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.btnType = ""
      this.reset();
    },
    // 表单重置
    reset() {
      this.allCheck = -1;
      this.form = {
        checkResult: null,
        snCode: null,
        indexName: null,
        indexType: null,
        headEndCheckType: null,
        remark: null,
      };
      this.snObj = {};
      this.radioObj = {};
      this.templateList = [];
      this.autoGenFlag = false;
      this.loading1 = false;
      this.exceptionLogList = [{}];
      this.snCodeAllList = [];
      this.fqcDisabled = false;
      this.snList = [];
      // 不合格数
      this.failedSncode = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      console.log(this.queryParams, "=====queryParams===");
      if (this.queryParams.time) {
        this.queryParams["provingTimeBegin"] =
          this.queryParams.time[0].split(" ")[0];
        this.queryParams["provingTimeEnd"] =
          this.queryParams.time[1].split(" ")[0];
      } else {
        this.queryParams["provingTimeBegin"] = null;
        this.queryParams["provingTimeEnd"] = null;
      }

      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.time = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleUserRole(row, type = null) {
      this.loading = true
      console.info(type)
      // this.statusQuery(row,type)
      selectUserRole("FQC_质检员工")
        .then((res) => {
          //判断是否是复核按钮
          if (type == 'fh') {
            this.btnType = 'fh';
            this.isReview = true;
            this.handleAdd2(row);
          } else {
            this.isReview = false;
            this.handleAdd(row);
          }
          this.loading = false
        })
        .catch(() => {
          console.log("qqqqqqqqq");
          this.loading = false
          return "false";
        });
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      // this.reset();
      this.indexCodeDisabled = false;
      this.open = true;
      this.QcFqcAcInspectionHead = row;
      this.form = { ...row };
      console.log(this.form, "========form==========");
      this.form.unqualifiedCode = undefined;
      this.form.qualifiedCode = undefined;
      this.title =
        row.productType == "DC"
          ? "FQC直流产品入库检验表"
          : row.productType == "AC"
            ? "FQC交流产品入库检验表"
            : row.productType == "VM"
              ? "FQC车载产品入库检验表"
              : "FQC直流产品入库检验表";
      this.optType = "add";
      //edit begin by zyj 2024/11/20 获取检验模板id
      // let id =
      //   row.productType == "DC"
      //     ? "10"
      //     : row.productType == "AC"
      //     ? "20"
      //     : row.productType == "VM"
      //     ? "21"
      //     : row.productType == "PCBA"
      //     ? "24"
      //     : "10";
      //     getFqcSnCode(this.form.inspectionNumber).then((response) => {
      //       this.snCodeAllList = response.data.map((item, index) => {
      //         return item.snCode;
      //       });
      //       if (this.form.fqcInspectionType == "0") {
      //         this.snList = this.snCodeAllList;
      //       }
      //     });
      //     this.templatePost(id);
      // 调用查询质检方案list接口
      this.getQualityinspection();
      let id = null;
      // getTemplateId(row.productCode).then((response) => {
      //   if (response.data) {
      //     id = response.data;
      //   } 
      //   return getFqcSnCode(this.form.inspectionNumber)
      //   // else {
      //   //   throw Error("没有模板");
      //   // }
      // })
      getFqcSnCode(this.form.inspectionNumber).then((response) => {
        this.snCodeAllList = Array.isArray(response.data)
          ? response.data
            .filter(item => item && item.snCode) // 过滤掉 null 或 snCode 为空的项
            .map(item => item.snCode)
          : [];
        if (this.form.fqcInspectionType == "0") {
          this.snList = this.snCodeAllList;
        }
        // this.templatePost(id);
      }).catch(err => {
        this.$message({
          message: err.message,
          type: "warning",
        });
      });

      //edit end by zyj 2024/11/20 获取检验模板id


      // this.getErrorlist(row.productType, id);
    },
    /** 复核 按钮操作 */
    handleAdd2(row) {
      this.indexCodeDisabled = false;
      this.open = true;
      this.optType = 'edit'
      // this.snCodeAllList =
      /**
      getCheckItems(row.id).then((response) => {
              if (response.data) {
                id = response.data;
                return getFqcSnCode(this.form.inspectionNumber)
              } else {
                throw Error("没有检测数据");
              }
            }).then((response) => {
              this.snCodeAllList = response.data.map((item, index) => {
                return item.snCode;
              });
              if (this.form.fqcInspectionType == "0") {
                this.snList = this.snCodeAllList;
              }
              this.templatePost(row.id);
            }).catch(err => {
              this.$message({
                message: err.message,
                type: "warning",
              });
            });
      **/
      getCheckItems(row.id).then((response) => {
        this.snCodeAllList = response.data.snCodeList
        this.templateList = response.data.itemList.map((item, index) => {
          return Object.assign({}, item, {
            attrObj: item.attr1 ? JSON.parse(item.attr1) : { type: "0" },
          })
        });
        //this.form.checkResult = this.templateList.filter(item=>item.checkResult==1).length == this.templateList.length?1:0;
        this.form = response.data.qcFqcAcInspectionHead;
        this.getSpanArr(response.data.itemList);
      }).catch(err => {
        this.$message({
          message: err.message,
          type: "warning",
        });
      });
    },
    /* 2024-12-26 djj 增加复核详情按钮 */
    handleReviewDetails(row) {
      this.$refs.reviewDetails.init(row)
    },

    // 获取sn列表
    snCodeQuery() { },
    /* 按钮 */
    submitFormBtn() {
      //如果是抽检
      if (this.form.fqcInspectionType == 1 && this.snList.length != this.form.sampleNumber) {
        this.$modal.msgError("抽样数量和 SN 码数量不一致");
        this.snList = []
        return false;
      }
      if (this.btnType == 'fh') {
        this.submitForm2()
      } else {
        this.submitForm()
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.fqcDisabled = true;
      this.isDrawerLoading = true;
      let QcFqcDto = {};
      let bool = false;


      QcFqcDto.qcInspectionResult = {
        productType: this.form.productType,
        exceptionLogList: this.exceptionLogList,
        inspectionType: "2",
        checkResult: this.form.checkResult,
        repairState: this.form.repairState,
      };

      QcFqcDto.qcFqcAcInspectionHead = {
        ...this.form,
      };
      delete QcFqcDto.qcFqcAcInspectionHead.pendingCheckUserIdQE;
      QcFqcDto.itemList = [];
      this.templateList.map((item, index) => {
        let type = item.attrObj.type;
        let attr2 = {};
        if (type == "2") {
          attr2.num = item.attrObj.num;
        } else if (type == "4") {
          attr2 = {
            lStandard: item.attrObj.lStandard,
            wStandard: item.attrObj.wStandard,
            hStandard: item.attrObj.hStandard,
            lNum: item.attrObj.lNum,
            wNum: item.attrObj.wNum,
            hNum: item.attrObj.hNum,
          };
        }
        QcFqcDto.itemList.push(
          Object.assign({}, item, {
            attr2: JSON.stringify(attr2),
          })
        );
      });
      QcFqcDto.snCodeList = this.snList;
      for (let j = 0; j < this.templateList.length; j++) {
        const element = this.templateList[j].checkResult;
        console.log(element);
        if (element === undefined) {
          bool = true;
        }
      }
      if (bool) {
        this.$message({
          message: "请填写检验结果！！！",
          type: "warning",
        });
        this.fqcDisabled = false;
        return;
      }
      this.$refs["form"].validate((valid, value) => {
        if (valid) {
          addInspection(QcFqcDto).then((response) => {
            this.$modal.msgSuccess("检验成功！");
            this.open = false;
            this.fqcDisabled = false;
            this.reset();
            this.getList();
            this.isDrawerLoading = false;
          }).catch(() => {
            this.fqcDisabled = false;
            this.isDrawerLoading = false;
          });
        } else {
          this.fqcDisabled = false;
          this.isDrawerLoading = false;
        }
      });
    },
    /** 复核 提交按钮 */
    submitForm2() {
      this.fqcDisabled = true;
      let QcFqcDto = {};
      let bool = false;
      QcFqcDto.qcInspectionResult = {
        productType: this.form.productType,
        exceptionLogList: this.exceptionLogList,
        inspectionType: "2",
        checkResult: this.form.checkResult,
        repairState: this.form.repairState,
      };

      QcFqcDto.qcFqcAcInspectionHead = {
        ...this.form,
      };
      QcFqcDto.itemList = [];
      this.templateList.map((item, index) => {
        let type = item.attrObj.type;
        let attr2 = {};
        if (type == "2") {
          attr2.num = item.attrObj.num;
        } else if (type == "4") {
          attr2 = {
            lStandard: item.attrObj.lStandard,
            wStandard: item.attrObj.wStandard,
            hStandard: item.attrObj.hStandard,
            lNum: item.attrObj.lNum,
            wNum: item.attrObj.wNum,
            hNum: item.attrObj.hNum,
          };
        }
        QcFqcDto.itemList.push(
          Object.assign({}, item, {
            attr2: JSON.stringify(attr2),
          })
        );
      });
      QcFqcDto.snCodeList = this.snList;
      for (let j = 0; j < this.templateList.length; j++) {
        const element = this.templateList[j].checkResult;
        console.log(element);
        if (element === undefined) {
          bool = true;
        }
      }
      if (bool) {
        this.$message({
          message: "请填写检验结果！！！",
          type: "warning",
        });
        this.fqcDisabled = false;
        return;
      }
      this.isDrawerLoading = true;
      this.$refs["form"].validate((valid, value) => {
        if (valid) {
          inspectionQE(QcFqcDto).then((response) => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.fqcDisabled = false;
            this.reset();
            this.getList();
            this.isDrawerLoading = false;
          }).catch(() => {
            this.fqcDisabled = false;
            this.isDrawerLoading = false;
          });
        } else {
          this.fqcDisabled = false;
          this.isDrawerLoading = false;
        }
      });
    },
    // 获取新增表格列表
    templatePost(id) {
      this.loading1 = true;
      let params = {
        pageNum: 1,
        pageSize: 999999,
        templateId: id || "18",
      };
      templateindexList(params).then((response) => {
        let list = [];
        response.rows.map((item, index) => {
          list.push(
            Object.assign({}, item, {
              attrObj: item.attr1 ? JSON.parse(item.attr1) : { type: "0" },
            })
          );
        });
        this.templateList = list;
        console.log(this.templateList, "=========list===========");
        this.getSpanArr(response.rows);
        this.loading1 = false;
      });
    },
    // 行合并
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex]; // 合并行数
        const _col = this.spanArr[rowIndex] > 0 ? 1 : 0; // 合并的列数
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    },
    // 按照类型合并
    getSpanArr(data) {
      this.spanArr = []; // tip: 后台获取完成数据后，一定要重置spanArr=[],避免出现合并混乱！！！！！
      if (data.length > 0) {
        for (let i = 0; i < data.length; i++) {
          // 当为第一行时
          if (i === 0) {
            this.spanArr.push(1);
            this.pos = 0;
          } else {
            // 判断当前值是否与上一行的【名称】相等，相等则进行合并
            if (data[i].indexType === data[i - 1].indexType) {
              this.spanArr[this.pos] += 1; // 合并单元格：合并的行数 +1
              this.spanArr.push(0); // 0代表单元格是不需要显示, 已经被合并的单元格
            } else {
              this.spanArr.push(1); // 1代表当前这行的数据需要被显示
              this.pos = i;
            }
          }
        }
      }
    },
    //全选按钮事件
    checkAllChange(value, i) {
      console.log(value, i, "=====iii=======");
      let objName = "checkResult" + i;
      let list = [];
      this.templateList.map((item, index) => {
        list.push(Object.assign({}, item, { [objName]: 1 }));
      });
      console.log(list);
      this.templateList = list;
    },
    // 判断是否显示打钩单选
    judegShow(attr) {
      return true;
    },
    // 判断当前是否是合格
    checkChange(value) {
      let str = "checkResult";
      let bool = this.templateList.every((item) => item[str] == 1);
      this.form.checkResult = bool ? 1 : 0;
    },
    // 异常记录增加
    errorAdd(item, i) {
      let obj = {};
      this.exceptionLogList.push(obj);
    },
    // 删除异常记录
    errorDel(index, i) {
      this.exceptionLogList.splice(index, 1);
    },
    //图片上传成功
    handleImgUplaoded(imgUrl, index) {
      this.exceptionLogList[index].fileName = imgUrl;
      // this.form.sopUrl = imgUrl;
    },
    //图片移除
    handleImgRemoved(imgUrl, index) {
      console.log(imgUrl);
      this.exceptionLogList[index].fileName = imgUrl;
    },
    inputStandard(e, row, index) {
      console.log(row, "=====row=====");
      let judType = row.attrObj.judType;
      let num = row.attrObj.num;
      let standard = row.attrObj.standard;
      let min = row.attrObj.min;
      let max = row.attrObj.max;
      if (judType == "0") {
        // =
        if (num == standard) {
          this.templateList[index].checkResult = 1;
        } else {
          this.templateList[index].checkResult = 0;
        }
      } else if (judType == "1") {
        // >=
        if (Number(num) >= Number(standard)) {
          console.log(num, "==1=");
          this.templateList[index].checkResult = 1;
        } else {
          console.log(num, "=0==");
          this.templateList[index].checkResult = 0;
        }
      } else if (judType == "2") {
        // <=
        if (Number(num) <= Number(standard)) {
          this.templateList[index].checkResult = 1;
        } else {
          this.templateList[index].checkResult = 0;
        }
      } else if (judType == "3") {
        if (Number(num) >= Number(min) && Number(num) <= Number(max)) {
          console.log(true, "=====");
          this.templateList[index].checkResult = 1;
        } else {
          this.templateList[index].checkResult = 0;
        }
      }
      let obj1 = { ...this.templateList[index] };
      this.$set(this.templateList, index, obj1);
      this.checkChange();
    },
    inputCheckout(e, row, index) {
      let lStandard = row.attrObj.lStandard;
      let wStandard = row.attrObj.wStandard;
      let hStandard = row.attrObj.hStandard;
      let lnum = row.attrObj.lNum;
      let wnum = row.attrObj.wNum;
      let hnum = row.attrObj.hNum;
      if (lnum == lStandard && wnum == wStandard && hnum == hStandard) {
        console.log(true, "=====");
        this.templateList[index].checkResult = 1;
      } else {
        this.templateList[index].checkResult = 0;
      }

      let obj1 = { ...this.templateList[index] };
      this.$set(this.templateList, index, obj1);
      this.checkChange();
    },
    // 详情
    handleView(row) {
      this.reset();
      this.openDetail = true;
      console.log(row, "领料单编号的row");
      this.$nextTick(() => {
        this.$refs.detailsList.init(row);
      });
      // const id = row.id;
      // this.QcFqcAcInspectionHead = row;
      // this.getErrorlist(row.productType, id);
      // getInspection(id).then(res => {
      //   console.log(res);
      //   let list = [];
      //   if (res.data && res.data.length > 0) {
      //     this.form = { ...res.data[0].qcFqcAcInspectionHead };
      //     // list = res.data[0].itemList;
      //     console.log(this.templateList, "=======itemList====");
      //     for (let i = 0; i < res.data[0].itemList.length; i++) {
      //       let obj = res.data[0].itemList[i];
      //       let attrList = res.data[0].itemList[i].attr2;
      //       obj.resultList = JSON.parse(attrList);
      //       obj.attrObj = obj.attr1 ? JSON.parse(obj.attr1) : { type: "0" };
      //       list.push(obj);
      //     }
      //   }
      //   for (let i = 0; i < res.data.length; i++) {
      //     this.snObj[`snCode${i}`] = res.data[i].snCode; // sncode
      //     if (res.data[i].qcInspectionResult) {
      //       // 异常数据
      //       this.failedSncode.push(res.data[i].qcInspectionResult);
      //     }
      //     // 处理表格数据
      //     for (let j = 0; j < res.data[i].itemList.length; j++) {
      //       list[j][`checkResult${i}`] = res.data[i].itemList[j].checkResult; // 检验结果
      //       if (list[j].attrObj.type == "2") {
      //         let attr2 = res.data[i].itemList[j].attr2
      //           ? JSON.parse(res.data[i].itemList[j].attr2)
      //           : {};
      //         list[j].attrObj[`num${i}`] = attr2.num;
      //       }
      //       if (list[j].attrObj.type == "4") {
      //         let attr2 = res.data[i].itemList[j].attr2
      //           ? JSON.parse(res.data[i].itemList[j].attr2)
      //           : {};
      //         list[j].attrObj[`lNum${i}`] = attr2.lNum;
      //         list[j].attrObj[`wNum${i}`] = attr2.wNum;
      //         list[j].attrObj[`hNum${i}`] = attr2.hNum;
      //       }
      //     }
      //   }
      //   // let qcobj = response.data?.qcInspectionResult || {};
      //   // this.form = { ...res.data, ...qcobj };
      //   // this.exceptionLogList = res.data?.qcInspectionResult
      //   //   ?.exceptionLogList || [{}];
      //   // let list = [];
      //   console.log(list, "=======list=====");
      //   this.templateList = list || [];
      //   this.open = true;
      //   this.title = "查看检验详情";
      //   this.optType = "view";
      //   this.getSpanArr(list || []);
      // });
    },
    handleViewBom(row) {
      this.reset();
      this.openDetailBom = true;
      console.log(row, "领料单编号的row");
      this.$nextTick(() => {
        this.$refs.detailsBom.init(row);
      });
    },

    //输入sn码校验是否正确
    snbutton(e) {
      console.log(e, "eeee");
      var myInputOrder = document.getElementById("sncode-input");
      myInputOrder.onkeydown = (even) => {
        console.log(even, "=====even=====");
        if (even.key == "Enter") {
          let params = {
            snCode: e,
            workorderCode: this.form.projectCode,
          };
          checkSncode(params).then((res) => {
            if (res.code == 200) {
              this.$modal.msgSuccess(res.msg);
            }
          });
        }
      };
    },
    selectChange(e) {
      console.log(e, "====e=====");
      if (e === "0") {
        this.snList = this.snCodeAllList;
      } else {
        this.snList = [];
      }
    },
    // 自动计算合格不合格数量
    autoInput(e, type, name) {
      if (e > this.form.quantityDeclared) {
        this.$message({
          message: "数量不允许超过报检数量！！！",
          type: "warning",
        });
        this.form[type] = 0;
      } else {
        this.form[name] = this.form.quantityDeclared - this.form[type];
      }
      // this.form[name] =  this.form.quantityDeclared - this.form[type]
    },
  },
};
</script>
<style scoped>
.tableItem .el-form-item__content {
  margin-left: 0px !important;
}

.tableItem ::v-deep .el-form-item__content {
  margin-left: 0px !important;
}

.headerDiv {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialogContent ::v-deep .el-upload--picture-card {
  width: 80px;
  height: 80px;
  line-height: 80px;
}

.dialogContent .el-table {
  font-size: 12px;
}

ul li {
  list-style: none;
}

.mInput {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
}

.el-icon-circle-plus-outline {
  font-size: 16px;
}

.el-icon-remove-outline {
  font-size: 16px;
}
</style>
